package com.lyz.dataStructure.algorithm.哔哩哔哩2020;/**
 * @Author:759057893@qq.com Lyz
 * @Date: ${Date} 18:58
 * @Description:
 **/

import java.util.Scanner;

/**
 *@Author:759057893@qq.com Lyz
 *@Date: 2019/8/20 18:58
 *@Description:
 **/
public class Main3 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N =sc.nextInt();
        int M = sc.nextInt();
        int[] w=new int[N];
        int[] v= new int[N];
        for(int i =0;i<N;i++){
            w[i] = sc.nextInt();
        }
        for(int i =0;i<N;i++){
            v[i] = sc.nextInt();
        }
        int max_value = maxValue(M,N,w,v);
        System.out.println(max_value);
    }
    public static int maxValue(int V,int N,int[] weight,int[] value){
        int[] dp = new int[V+1];
        for(int i =1;i<N+1;i++){
            for(int j =V;j>=weight[i-1];j--){
                dp[j] = Math.max(dp[j-weight[i-1]]+value[i-1],dp[j]);
            }
        }
        return dp[V];
    }
}
